package com.example.boot1;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class AQSDemo {
    private static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        new Thread(() -> {
            lock.lock();
            try{
                System.out.println("---thread A come in---");
                try{ TimeUnit.MINUTES.sleep(10);} catch(Exception e){e.printStackTrace();}

            }catch(Exception e){
                e.printStackTrace();
            }finally{
                lock.unlock();
            }
        }, "A").start();


        new Thread(() -> {
            lock.lock();
            try{
                System.out.println("---thread B come in---");
            }catch(Exception e){
                e.printStackTrace();
            }finally{
                lock.unlock();
            }
        }, "B").start();

        new Thread(() -> {
            lock.lock();
            try{
                System.out.println("---thread C come in---");
            }catch(Exception e){
                e.printStackTrace();
            }finally{
                lock.unlock();
            }
        }, "C").start();

    }
}
